<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="../component/pear/css/pear.css" />
    <link rel="stylesheet" href="../admin/css/other/console1.css" />
    <style>
        .empty{
            margin-top: 50px;
            text-align: center;
            margin-bottom: 50px;
        }
        .empty .desc{
            color: dimgray;
            margin-top: 10px;
        }
    </style>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-inline">
                    <input type="text" name="realName" placeholder="" class="layui-input">
                </div>
                <label class="layui-form-label">账号</label>
                <div class="layui-input-inline">
                    <input type="text" name="username" placeholder="" class="layui-input">
                </div>
                <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="user-query">
                    <i class="layui-icon layui-icon-search"></i>
                    查询
                </button>
                <button type="reset" class="pear-btn pear-btn-md">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </form>
    </div>
</div>
 <div class="layui-row layui-col-space10">
     <div class="layui-col-md3">
         <div class="layui-card">
             <div class="layui-card-body">
                 <ul  class="list">
                     <li class="list-item  table-node" th:each="table:${tables}">
                         <span class="title" th:text="${table.TABLE_NAME}"></span>
                     </li>
                 </ul>
             </div>
         </div>
     </div>
     <div class="layui-col-md9">
         <div class="layui-card">
             <div class="layui-card-body">
                 <div class="empty">
                     <img src="../admin/images/empty.svg"/>
                     <div class="desc">暂无数据</div>
                 </div>
                 <table id="user-table" lay-filter="user-table">
                 </table>
             </div>
         </div>
     </div>
 </div>

<script type="text/html" id="user-toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
        <i class="layui-icon layui-icon-add-1"></i>
        新增
    </button>
    <button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
        <i class="layui-icon layui-icon-delete"></i>
        删除
    </button>
</script>

<script type="text/html" id="user-bar">
    <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></button>
    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
</script>

<script type="text/html" id="user-enable">
    <input type="checkbox" name="enable" value="{{d.powerId}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="power-enable" checked>
</script>

<script type="text/html" id="user-select">
    <select name="openType" id="openType">
        <option value=""></option>
        <option value="0" selected>模糊查询</option>
        <option value="1">签页</option>
    </select>
</script>

<script type="text/html" id="generator-comment">
    {{#if (d.COLUMN_COMMENT == "") { }}
    <span>无备注</span>
    {{# }else{ }}
    <span>{{d.COLUMN_COMMENT}}</span>
    {{# } }}
</script>


<script src="../component/layui/layui.js"></script>
<script src="../component/pear/pear.js"></script>
<script>
    layui.use(['table', 'form', 'jquery'], function() {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;

        let cols = [
            [
                {
                    title: '字段名称',
                    field: 'COLUMN_NAME'
                },{
                    title: '字段备注',
                    field: 'COLUMN_COMMENT',
                    templet: '#generator-comment'
                },{
                    title: '数据类型',
                    field: 'COLUMN_TYPE'
                },{
                    title: '是否为空',
                    field: 'IS_NULLABLE',
                    align: 'center'
                },{
                    title: '查询(可选)',
                    field: 'IS_NULLABLE',
                    align: 'center'
                 },{
                    title: '列表显示',
                    field: 'IS_NULLABLE',
                    align: 'center',
                    templet: '#user-enable'
                },{
                    title: '字段验证(可选)',
                    field: 'IS_NULLABLE',
                    align: 'center'
                }
            ]
        ]

        $(".table-node").click(function(){
            $(".empty").remove();
            table.render({
                elem: '#user-table',
                url: '/generator/queryColumn?tableName='+$(this).find("span").text(),
                page: true,
                cols: cols,
                page: false,
                skin: 'line',
                toolbar: false,
                defaultToolbar: false
            });
        })

        form.on('submit(user-query)', function(data) {
            table.reload('user-table', {
                where: data.field
            })
            return false;
        });

        window.refresh = function(param) {
            table.reload('user-table');
        }
    })
</script>
</body>
</html>
